(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
authorRichard M. Stallman <rms@gnu.org>
Sun, 16 May 1993 22:31:04 +0000 (22:31 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 16 May 1993 22:31:04 +0000 (22:31 +0000)
Try first with small overlay_vec, then use a big enough one.

src/xfaces.c

index e450b3aa8e501114fd35b23ee55aa62ec6d4c1f0..febafc8066a2a58cf5c20302c43d78b315002a43 100644 (file)
@@ -136,6 +136,8 @@ int next_face_id;
 /* The number of the face to use to indicate the region.  */
 int region_face;
 
+/* This is what appears in a slot in a face to signify that the face
+   does not specify that display aspect.  */
 #define FACE_DEFAULT (~0)
 
 Lisp_Object Qface, Qwindow, Qpriority;
@@ -638,7 +640,6 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr)
   int i, j, noverlays;
   int facecode;
   Lisp_Object *overlay_vec;
-  int len;
   struct sortvec *sortvec;
   Lisp_Object frame;
   int endpos;
@@ -666,10 +667,23 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr)
 
   {
     int next_overlay;
+    int len;
+
+    /* First try with room for 40 overlays.  */
+    len = 40;
+    overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
+    
+    noverlays = overlays_at (pos, 0, &overlay_vec, &len, &next_overlay);
+
+    /* If there are more than 40,
+       make enough space for all, and try again.  */
+    if (noverlays > len)
+      {
+       len = noverlays;
+       overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
+       noverlays = overlays_at (pos, 0, &overlay_vec, &len, &next_overlay);
+      }
 
-    len = 10;
-    overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
-    noverlays = overlays_at (pos, &overlay_vec, &len, &next_overlay);
     if (next_overlay < endpos)
       endpos = next_overlay;
   }
@@ -763,8 +777,6 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr)
        merge_faces (FRAME_FACES (f) [region_face], &face);
     }
 
-  xfree (overlay_vec);
-
   *endptr = endpos;
 
   return intern_frame_face (f, &face);